package com.zxw.hotel.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zxw.hotel.common.Pageinfo;
import com.zxw.hotel.dao.FacilityDao;
import com.zxw.hotel.model.Facility;
import com.zxw.hotel.service.FacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FacilityServiceIpl implements FacilityService {
    private FacilityDao facilityDao;
    @Autowired
    public FacilityServiceIpl(FacilityDao facilityDao) {
        this.facilityDao = facilityDao;
    }
    @Override
    public List<Facility> getAll(Pageinfo pageinfo, Facility facility) {
        try(Page<?> __= PageHelper.startPage(pageinfo.getPageNo(),pageinfo.getPageSize())){
            return facilityDao.getall(facility);
        }

    }

    @Override
    public int add(Facility facility) {
        if(facility.getFacilityId()==null||facility.getFacilityName()==null||
                facility.getFacilityId().isEmpty()||facility.getFacilityName().isEmpty()){
            return 0;
        }
        try{
            return facilityDao.add(facility);
        }catch (Exception e){
            return 0;
        }

    }

    @Override
    public int update(Facility facility) {
        if(facility.getFacilityId()==null||facility.getFacilityName()==null||
                facility.getFacilityId().isEmpty()||facility.getFacilityName().isEmpty()){
            return 0;
        }
        try{
            int update = facilityDao.update(facility);
            return update;
        }catch (Exception e){
            return 0;
        }


    }

    @Override
    public int delete(Integer[] ids) {
        return facilityDao.delete(ids);
    }
}
